Everyone has done it at least once. An item that you weren't intending to sell gets mistakenly sold to the vendor because you weren't paying attention.
There should be at least a 15-30 min window (or until you leave the town/outpost) where you can buy back the stuff you just sold.
Agree.
I've done that myself a few times. I was like...oh crud! lol
I started putting items I want to keep in my last bag and putting something that can't be merched in front of them. That helps, but still it would be a nice feature to have.